module.exports = function (grunt) {
    /**
     * 是否是调试模式
     * @type {boolean}
     */
    var debug = true;
    var gulify_debug_options = {
        banner: "",
        separator: ';',
        compress: false,//不启用压缩
        preserveComments: 'all',//保留注释
        mangle: false,//不压缩变量名
        beautify: true,//压缩后进行排版
    };
    var gulify_run_options = {
        banner: "",
        separator: ';',
        mangle: true,
        beautify: false,
    };

    function getConfig(name) {
        if (!name) {
            return;
        }
        switch (name) {
            case 'uglify':
                if (debug) {
                    return gulify_debug_options;
                } else {
                    return gulify_run_options;
                }
            case"csswatch":
                if (debug) {
                    return "cssmin:base";
                } else {
                    return "cssmin:base"
                }

        }
    }

    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),
        /**
         * 压缩js文件
         */
        uglify: {
            options: getConfig("uglify"),
            hello: {
                src: [
                    './bower_components/jquery/dist/jquery.js',
                    './resource/projectjs/hello/hello-jq.js',
                    './resource/projectjs/hello/hello-ng-controller.js'
                ],
                dest: 'build/js/hello.min.js'
            },
            hello2: {
                src: [
                    './bower_components/jquery/dist/jquery.js',
                    './resource/projectjs/hello/hello-jq.js',
                    './resource/projectjs/hello/hello-ng-controller.js'
                ],
                dest: 'build/js/hello2.min.js'
            }
        },
        sass: {
            myApp: {
                files: {
                    './resource/css/project.css': './resource/sass/**/*.scss'
                }
            }
        },
        compass: {
            myApp: {
                options: {
                    config: 'config.rb',
                }
            }
        },
        cssmin: {
            options: {
                report: "gzip",
                compress: false,//不启用压缩
                preserveComments: 'all',//保留注释
                mangle: false,//不压缩变量名
                beautify: true,//压缩后进行排版
                shorthandCompacting: true,
                roundingPrecision: -1
            },
            base: {
                files: {
                    './build/css/buildApp.css': ['./resource/css/**/*.css']
                }
            }
        },
        watch: {
            jsyasuo: {
                files: ['./resource/projectjs/**/*.js', 'Gruntfile.js'],
                tasks: ['uglify']
            },
            cssyasuo: {
                files: ['./resource/sass/**/*.scss', './resource/css/**/*.css', 'Gruntfile.js'],
                tasks: ['compass:myApp', 'cssmin:base']
            }
        },
        reload: {
            port: 35729,
            liveReload: {},
            proxy: {
                host: "localhost",
                port: 8080
            }
        }
    });
    /**
     * 载入需要的模块
     *  require('load-grunt-tasks')(grunt);
     *  js合并压缩
     */
    grunt.loadNpmTasks('grunt-contrib-uglify');
    /**
     *  sass编译
     */
    grunt.loadNpmTasks('grunt-contrib-sass');
    /**
     *  sass框架 compass
     */
    grunt.loadNpmTasks('grunt-contrib-compass');
    /**
     * css压缩
     */
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    /**
     * css合并
     */
    grunt.loadNpmTasks('grunt-contrib-csslint');
    /**
     * 监控
     */
    grunt.loadNpmTasks('grunt-contrib-watch');
    /**
     * 浏览器监控
     */
    //grunt.loadNpmTasks("grunt-reload");
    /**
     * 注册任务 运行方法 grunt yasuo
     */
    grunt.registerTask('ugtask', ['uglify:hello']);

    /**
     * 默认的运行方法
     */
    grunt.registerTask("default", ["watch"]);

    grunt.registerTask('xx', 'asdasd', function () {
        grunt.log.writeln('xxx');
        grunt.log.writeln('xxx');
        grunt.log.writeln('xxx');
    });
};